#include <QApplication>

#include "DGVFile.h"

const string filename = "out_test.txt";

void printLine(QStringList &strs);

int main(int argc, char *argv[])
{
	QApplication app(argc,argv);
	DGVFile file;

    cerr << ">| File Class Test" << endl;
    cerr << ">| Copyright Shekhar S. Chandra, 2008" << endl;
    cerr << ">| Original file: " << filename << endl;

    ///Write Test
	if(!file.open(filename.c_str(),"w"))
    {
        cerr << "ERROR: Opening file." << endl;
        app.exit();
    }

	QString text;

	text = "#This is a test file for DGVFile class";
	cerr << text.toStdString() << endl;
	file.writeLine(text);
	text = "This is some data";
	cerr << text.toStdString() << endl;
	file.writeLine(text);
	text = "This is data with # comments";
	cerr << text.toStdString() << endl;
	file.writeLine(text);
	text = "More data";
	cerr << text.toStdString() << endl;
	file.writeLine(text);
	file.close();

    ///Read Test
    cerr << ">| Read written file:" << endl;
    if(!file.open(filename.c_str(),"r"))
    {
        cerr << "ERROR: Opening file." << endl;
        app.exit();
    }

    QStringList line;
    while(!file.atEnd())
    {
        line = file.readNextLine();
        printLine(line);
    }
	file.close();

	app.exit();
}

void printLine(QStringList &strs)
{
    //cerr << "Size: " << strs.size() << endl;
    for(int j = 0; j < strs.size(); j ++)
        cerr << "'" << strs[j].toStdString() << "' ";
    if(strs.size() != 0)
        cerr << endl;
}
